package ossops

import (
	"avenssi/config"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"log"
)

var EP string
var AK string
var SK string

func init()  {
	AK = ""
	SK = ""
	EP = config.GetOssAddr()
}

func uploadToOss(filename,path,bn string)bool{
	client,err := oss.New(EP,AK,SK)
	if err != nil {
		log.Printf("init oss service error :%s",err)
		return false
	}
	bucket ,err := client.Bucket(bn)
	if err != nil {
		log.Printf("Getting bucket error :%s",err)
		return false
	}

	err=bucket.UploadFile(filename,path,500*1024,oss.Routines(3))//并发传
	if err != nil{
		log.Printf("uploading object error :%s",err)
		return false
	}
	return true
}

func DeleteObject(filename,bn string)bool  {
	client,err := oss.New(EP,AK,SK)
	if err != nil {
		log.Printf("init oss service error :%s",err)
		return false
	}
	bucket ,err := client.Bucket(bn)
	if err != nil {
		log.Printf("Getting bucket error :%s",err)
		return false
	}
	err = bucket.DeleteObject(filename)
	if err != nil{
		log.Printf("delete object error :%s",err)
		return false
	}
	return true
}